package com.air;

import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.By;

public class AuthenticationPage extends BasePage {

    //Elements
    String pageTitle = "Authenticate";
    By userName = By.name("txtUserName");
    By password = By.name("txtPassword");
    By submit = By.cssSelector("input[type=\"submit\"]");

    public AuthenticationPage() {
    }

    public HomePage doAuthenticate(JSONObject data) {
        try {
            checkPageTitle(pageTitle);
            clearAndType(userName, data.getString("UserName"));
            clearAndType(password, data.getString("Password"));
            click(submit);
        } catch (JSONException e) {
            verificationErrors.append(e.toString());
        } catch (Error e) {
            verificationErrors.append(e.toString());
        }
        return new HomePage();
    }
}

